/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package freewolf;

import com.puzzud.engine.core.Entity;
import com.puzzud.engine.input.InputKeyboard;
import com.puzzud.engine.input.InputMouse;
import com.puzzud.engine.utility.GameShell;
import com.puzzud.engine.video.VideoDisplay;
import com.puzzud.engine.video.VideoImage;
import com.puzzud.engine.video.VideoSprite;
import java.util.Vector;

/**
 *
 * @author puzzud
 */
public class GamePanel extends GameShell
{
    VideoDisplay videoDisplay;

    InputKeyboard keyboard;
    InputMouse mouse;

    VideoImage blockGraphicsSourceImage;
    VideoSprite blockGraphicsSpriteList[];

    Text roomNumberText;
    Text heroRoomPositionText;

    //MoveableItem mouseCursor;
    //Point mouseCursorAndItemDelta = new Point( 0,0 );

    //Random randomGenerator = new Random();

    int selectedBlockGraphicIndex = 0;
    int unHighLightedIndex = 1;
    boolean isDrawingBlockGraphicsSample = false;

    boolean mouseAim = false;

    int roomBlockOffsetX    = 2;
    int roomBlockOffsetY    = 2;

    Room currentRoom;
    Vector<Room> roomList;

    Person hero;
    Vector<Person> enemyList;

    @Override
    public void initialize()
    {
        keyboard = getKeyboard();
	mouse = getMouse();

        initializeGraphics();
        
        initializeCastle();
        initializeHero();
    }

    @Override
    public VideoDisplay initializeVideoDisplay()
    {
        videoDisplay = new VideoDisplay( 320, 240, this );

        return( videoDisplay );
    }

    public void initializeGraphics()
    {
        videoDisplay = getVideoDisplay();
        videoDisplay.setFrameRate( 33 );
        videoDisplay.setBackgroundColor( c64.Info.colorList[c64.Info.COLOR_BLACK] );
        videoDisplay.setPrintColor( c64.Info.colorList[c64.Info.COLOR_WHITE] );

        initializeBlockGraphics();

        roomNumberText = new Text( videoDisplay, blockGraphicsSpriteList );
        roomNumberText.setPosition( Room.WIDTH / 2, 0 );

        heroRoomPositionText = new Text( videoDisplay, blockGraphicsSpriteList );
        heroRoomPositionText.setPosition( 0, 0 );
    }

    public void initializeBlockGraphics()
    {
        blockGraphicsSourceImage = new VideoImage( this );
        blockGraphicsSourceImage.load( "/graphics/block_graphics.png" );

        blockGraphicsSpriteList = new VideoSprite[BlockGraphic.NUMBER_OF_BLOCK_GRAPHICS];

        int index;
        for( index = 0; index < BlockGraphic.NUMBER_OF_BLOCK_GRAPHICS; index++ )
        {
            blockGraphicsSpriteList[index] = new VideoSprite(
                    BlockGraphic.WIDTH,
                    BlockGraphic.HEIGHT,
                    VideoSprite.SPRITE_ATTR_SINGLE_FRAME,
                    this );

            blockGraphicsSpriteList[index].loadFrame(
                    blockGraphicsSourceImage,
                    ( index % BlockGraphic.NUMBER_OF_BLOCK_GRAPHICS_WIDE ) * BlockGraphic.WIDTH,
                    ( index / BlockGraphic.NUMBER_OF_BLOCK_GRAPHICS_WIDE ) * BlockGraphic.HEIGHT,
                    VideoSprite.EXTRACT_MODE_ABS );

            blockGraphicsSpriteList[index].setColor( c64.Info.colorList[c64.Info.COLOR_WHITE] );
            blockGraphicsSpriteList[index].setAlpha( 1.0f );
        }
    }

    @Override
    public void shutdown()
    {
        
    }

    @Override
    public void loop()
    {
        keyboardInput();
        mouseInput();
        
        movePeople();
    }

    public void keyboardInput()
    {
        if( keyboard.getKeyState( InputKeyboard.KEY_SPACE ) == InputKeyboard.KEY_STATE_PRESSED )
        {
            isDrawingBlockGraphicsSample = !isDrawingBlockGraphicsSample;
        }

        if( isDrawingBlockGraphicsSample == true )
        {
            keyboardInputSampleGraphics();
        }
        else
        {
            keyboardInputPlayer();
            keyboardInputRoomChange();
        }
    }

    public void mouseInput()
    {
        if( mouse.getButtonState( 2 ) == InputMouse.BUTTON_STATE_PRESSED )
        {
            mouseAim = !mouseAim;

            if( mouseAim == false )
            {
                hero.setAim( 0, 0 );
            }

            // DEBUG:
            //System.out.println( "mouseInput():BUTTON_STATE_DOWN, " + mouseAim );
        }

        mouseInputPlayerAimDirection();
    }

    public void keyboardInputPlayer()
    {
        if( hero == null )
        {
            return;
        }

        if( keyboard.checkKey( InputKeyboard.KEY_LEFT_CONTROL ) )
        {
            if( mouseAim == false )
            {
                keyboardInputPlayerAimDirection();
            }
        }
        else
        {
            keyboardInputPlayerMoveDirection();
        }
    }

    public void keyboardInputPlayerMoveDirection()
    {
        if( hero == null )
        {
            return;
        }

        if( keyboard.checkKey( InputKeyboard.KEY_W ) )
        {
            hero.setYVelocity( -1 );
        }
        else
        if( keyboard.checkKey( InputKeyboard.KEY_S ) )
        {
            hero.setYVelocity( 1 );
        }
        else
        {
            hero.setYVelocity( 0 );
        }

        if( keyboard.checkKey( InputKeyboard.KEY_A ) )
        {
            hero.setXVelocity( -1 );
        }
        else
        if( keyboard.checkKey( InputKeyboard.KEY_D ) )
        {
            hero.setXVelocity( 1 );
        }
        else
        {
            hero.setXVelocity( 0 );
        }
    }

    public void keyboardInputPlayerAimDirection()
    {
        if( hero == null )
        {
            return;
        }

        if( keyboard.checkKey( InputKeyboard.KEY_W ) )
        {
            hero.setYAim( -1 );
        }
        else
        if( keyboard.checkKey( InputKeyboard.KEY_S ) )
        {
            hero.setYAim( 1 );
        }
        else
        {
            hero.setYAim( 0 );
        }
        
        if( keyboard.checkKey( InputKeyboard.KEY_A ) )
        {
            hero.setXAim( -1 );
        }
        else
        if( keyboard.checkKey( InputKeyboard.KEY_D ) )
        {
            hero.setXAim( 1 );
        }
        else
        {
            hero.setXAim( 0 );
        }
    }

    public void keyboardInputRoomChange()
    {
        Room adjacentRoom;

        if( currentRoom == null )
        {
            return;
        }

        if( keyboard.getKeyState( InputKeyboard.KEY_UP ) == InputKeyboard.KEY_STATE_PRESSED )
        {
            adjacentRoom = currentRoom.getAdjacentRoom( Room.NORTH );

            if( adjacentRoom != null )
            {
                currentRoom = adjacentRoom;
                loadCurrentRoom();
            }
        }
        else
        if( keyboard.getKeyState( InputKeyboard.KEY_DOWN ) == InputKeyboard.KEY_STATE_PRESSED )
        {
            adjacentRoom = currentRoom.getAdjacentRoom( Room.SOUTH );

            if( adjacentRoom != null )
            {
                currentRoom = adjacentRoom;
                loadCurrentRoom();
            }
        }
        
        if( keyboard.getKeyState( InputKeyboard.KEY_LEFT ) == InputKeyboard.KEY_STATE_PRESSED )
        {
            adjacentRoom = currentRoom.getAdjacentRoom( Room.WEST );

            if( adjacentRoom != null )
            {
                currentRoom = adjacentRoom;
                loadCurrentRoom();
            }
        }
        else
        if( keyboard.getKeyState( InputKeyboard.KEY_RIGHT ) == InputKeyboard.KEY_STATE_PRESSED )
        {
            adjacentRoom = currentRoom.getAdjacentRoom( Room.EAST );

            if( adjacentRoom != null )
            {
                currentRoom = adjacentRoom;
                loadCurrentRoom();
            }
        }
    }

    public void keyboardInputSampleGraphics()
    {
        if( keyboard.checkKey( InputKeyboard.KEY_LEFT ) )
        {
            if( selectedBlockGraphicIndex > 0 )
            {
                unHighLightedIndex = selectedBlockGraphicIndex;
                selectedBlockGraphicIndex--;
            }
        }

        if( keyboard.checkKey( InputKeyboard.KEY_RIGHT ) )
        {
            if( selectedBlockGraphicIndex < BlockGraphic.NUMBER_OF_BLOCK_GRAPHICS - 1 )
            {
                unHighLightedIndex = selectedBlockGraphicIndex;
                selectedBlockGraphicIndex++;
            }
        }

        if( keyboard.checkKey( InputKeyboard.KEY_UP ) )
        {
            if( selectedBlockGraphicIndex - BlockGraphic.NUMBER_OF_BLOCK_GRAPHICS_WIDE > 0 )
            {
                unHighLightedIndex = selectedBlockGraphicIndex;
                selectedBlockGraphicIndex -= BlockGraphic.NUMBER_OF_BLOCK_GRAPHICS_WIDE;
            }
        }

        if( keyboard.checkKey( InputKeyboard.KEY_DOWN ) )
        {
            if( selectedBlockGraphicIndex + BlockGraphic.NUMBER_OF_BLOCK_GRAPHICS_WIDE < BlockGraphic.NUMBER_OF_BLOCK_GRAPHICS )
            {
                unHighLightedIndex = selectedBlockGraphicIndex;
                selectedBlockGraphicIndex += BlockGraphic.NUMBER_OF_BLOCK_GRAPHICS_WIDE;
            }
        }
    }

    public void mouseInputPlayerAimDirection()
    {
        if( hero == null )
        {
            return;
        }

        if( mouseAim == false )
        {
            return;
        }

        int mx = ( int )( ( ( float )mouse.getXPosition() / videoDisplay.getXScale() ) ) / BlockGraphic.WIDTH;
        int my = ( int )( ( ( float )mouse.getYPosition() / videoDisplay.getYScale() ) ) / BlockGraphic.HEIGHT;

        mx -= 1;
        my -= 1;

        if( mx < hero.getXPosition() - 2 )
        {
            hero.setXAim( -1 );
        }
        else
        if( mx > hero.getXPosition() + 2 )
        {
            hero.setXAim( 1 );
        }
        else
        {
            hero.setXAim( 0 );
        }

        if( my < hero.getYPosition() - 2 )
        {
            hero.setYAim( -1 );
        }
        else
        if( my > hero.getYPosition() + 2 )
        {
            hero.setYAim( 1 );
        }
        else
        {
            hero.setYAim( 0 );
        }

        // DEBUG:
        //System.out.println( mx + ":" + my + "..." + hero.getXPosition() + ":" + hero.getYPosition()
        //        + "..." + hero.getXAim() + ":" + hero.getYAim() );
    }

    public void movePeople()
    {
        moveHero();
        checkHeroRoomBounds();
    }

    public void moveHero()
    {
        heroRoomPositionText.setString( hero.getXPosition() + "," + hero.getYPosition() );

        hero.move();
    }

    public void checkHeroRoomBounds()
    {
        Room nextRoom = null;

        if( hero.getYPosition() < 0 )
        {
            nextRoom = currentRoom.getAdjacentRoom( Room.NORTH );

            if( nextRoom != null )
            {
                hero.setYPosition( Room.HEIGHT );
            }
            else
            {
                hero.setYVelocity( 0 );
                hero.setYPosition( 0 );
            }
        }
        else
        if( hero.getYPosition() > Room.HEIGHT )
        {
            nextRoom = currentRoom.getAdjacentRoom( Room.SOUTH );

            if( nextRoom != null )
            {
                hero.setYPosition( 0 );
            }
            else
            {
                hero.setYVelocity( 0 );
                hero.setYPosition( Room.HEIGHT );
            }
        }

        if( nextRoom == null )
        {
            if( hero.getXPosition() < 0 )
            {
                nextRoom = currentRoom.getAdjacentRoom( Room.WEST );

                if( nextRoom != null )
                {
                    hero.setXPosition( Room.WIDTH );
                }
                else
                {
                    hero.setXVelocity( 0 );
                    hero.setXPosition( 0 );
                }
            }
            else
            if( hero.getXPosition() > Room.WIDTH )
            {
                nextRoom = currentRoom.getAdjacentRoom( Room.EAST );

                if( nextRoom != null )
                {
                    hero.setXPosition( 0 );
                }
                else
                {
                    hero.setXVelocity( 0 );
                    hero.setXPosition( Room.WIDTH );
                }
            }
        }

        if( nextRoom != null )
        {
            if( nextRoom != currentRoom )
            {
                currentRoom = nextRoom;
                loadCurrentRoom();
            }
        }
    }

    @Override
    public void draw()
    {
        drawRoom();

        if( isDrawingBlockGraphicsSample == true )
        {
            drawBlockGraphicsSample2();
        }

        drawPeople();
    }

    public void drawRoom()
    {
        blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_HORIZONTAL].setColor( c64.Info.colorList[c64.Info.COLOR_BROWN] );
        blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_VERTICAL].setColor( c64.Info.colorList[c64.Info.COLOR_BROWN] );

        int x, y;

        // Draw north wall.
        if( currentRoom.getAdjacentRoom( Room.NORTH ) == null )
        {
            blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_VERTICAL].setPosition( roomBlockOffsetX * BlockGraphic.WIDTH, roomBlockOffsetY * BlockGraphic.HEIGHT );
            videoDisplay.draw( blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_VERTICAL] );

            blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_HORIZONTAL].setYPosition( roomBlockOffsetY * BlockGraphic.HEIGHT );
            for( x = roomBlockOffsetX + 1; x < Room.WIDTH + roomBlockOffsetX - 1; x++ )
            {
                blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_HORIZONTAL].setXPosition( x * BlockGraphic.WIDTH );
                videoDisplay.draw( blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_HORIZONTAL] );
            }

            blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_VERTICAL].setPosition( x * BlockGraphic.WIDTH, roomBlockOffsetY * BlockGraphic.HEIGHT );
            videoDisplay.draw( blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_VERTICAL] );
        }

        // Draw south wall.
        if( currentRoom.getAdjacentRoom( Room.SOUTH ) == null )
        {
            blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_HORIZONTAL].setYPosition( ( roomBlockOffsetY + Room.HEIGHT - 1 ) * BlockGraphic.HEIGHT );
            for( x = roomBlockOffsetX; x < Room.WIDTH + roomBlockOffsetX; x++ )
            {
                blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_HORIZONTAL].setXPosition( x * BlockGraphic.WIDTH );
                videoDisplay.draw( blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_HORIZONTAL] );
            }
        }

        // Draw west wall.
        if( currentRoom.getAdjacentRoom( Room.WEST ) == null )
        {
            blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_VERTICAL].setXPosition( roomBlockOffsetX * BlockGraphic.WIDTH );
            for( y = roomBlockOffsetY; y < Room.HEIGHT + roomBlockOffsetY - 1; y++ )
            {
                blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_VERTICAL].setYPosition( y * BlockGraphic.HEIGHT );
                videoDisplay.draw( blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_VERTICAL] );
            }
        }

        // Draw east wall.
        if( currentRoom.getAdjacentRoom( Room.EAST ) == null )
        {
            blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_VERTICAL].setXPosition( ( roomBlockOffsetX + Room.WIDTH - 1 ) * BlockGraphic.WIDTH );
            for( y = roomBlockOffsetY; y < Room.HEIGHT + roomBlockOffsetY - 1; y++ )
            {
                blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_VERTICAL].setYPosition( y * BlockGraphic.HEIGHT );
                videoDisplay.draw( blockGraphicsSpriteList[BlockGraphic.INDEX_WALL_VERTICAL] );
            }
        }

        roomNumberText.print();
    }

    private void drawBlockGraphicsSample()
    {
        int index;
        for( index = 0; index < BlockGraphic.NUMBER_OF_BLOCK_GRAPHICS; index++ )
        {
            blockGraphicsSpriteList[index].setPosition(
                    24 + ( index % BlockGraphic.NUMBER_OF_BLOCK_GRAPHICS_WIDE ) * BlockGraphic.WIDTH,
                    32 + ( index / BlockGraphic.NUMBER_OF_BLOCK_GRAPHICS_WIDE ) * BlockGraphic.HEIGHT );

            videoDisplay.draw( blockGraphicsSpriteList[index] );
        }

        blockGraphicsSpriteList[selectedBlockGraphicIndex].setColor( c64.Info.colorList[c64.Info.COLOR_YELLOW] );
        blockGraphicsSpriteList[unHighLightedIndex].setColor( c64.Info.colorList[c64.Info.COLOR_WHITE] );

        blockGraphicsSpriteList[selectedBlockGraphicIndex].setPosition( 128, 120 );
        videoDisplay.draw( blockGraphicsSpriteList[selectedBlockGraphicIndex] );
        videoDisplay.print( ((Integer)selectedBlockGraphicIndex).toString(), 128, 144 );
    }

    public void drawBlockGraphicsSample2()
    {
        int x, y;
        for( y = 0; y < Room.HEIGHT; y++ )
        {
            for( x = 0; x < Room.WIDTH; x++ )
            {
                blockGraphicsSpriteList[0].setPosition(
                        ( roomBlockOffsetX * BlockGraphic.WIDTH ) + ( x * BlockGraphic.WIDTH ),
                        ( roomBlockOffsetY * BlockGraphic.HEIGHT ) + ( y * BlockGraphic.HEIGHT ) );

                videoDisplay.draw( blockGraphicsSpriteList[0] );
            }
        }
    }

    public void drawBlock( int index, int x, int y, float color[] )
    {
        blockGraphicsSpriteList[index].setColor( color );
        blockGraphicsSpriteList[index].setPosition( x * BlockGraphic.WIDTH, y * BlockGraphic.HEIGHT );
        videoDisplay.draw( blockGraphicsSpriteList[index] );
    }

    public void drawPeople()
    {
        drawHero();
        drawEnemies();
    }

    public void drawHero()
    {
        drawPerson( hero );

        heroRoomPositionText.print();
    }

    public void drawEnemies()
    {
        int index;

        for( index = 0; index < enemyList.size(); index++ )
        {
            drawPerson( enemyList.get( index ) );
        }
    }

    public void drawPerson( Person person )
    {
        int x, y;
        int xv, yv;

        int headGraphicIndex;
        float headColor[];
        
        int torsoGraphicIndex;
        float clothesColor[];

        int headGraphicIndexOffset; // Used from direction to determine which graphic to use.

        int leftArmGraphicIndex;
        int rightArmGraphicIndex;

        // Determine arm graphics, depending on which way person is aiming.
        if( person.getXAim() < 0 )
        {
            if( person.getYAim() < 0 )
            {
                leftArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_LEFT_NW;
                rightArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_RIGHT_NW;
            }
            else
            if( person.getYAim() >  0 )
            {
                leftArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_LEFT_SW;
                rightArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_RIGHT_SW;
            }
            else
            {
                leftArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_LEFT_W;
                rightArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_RIGHT_W;
            }

            headGraphicIndexOffset = 1;
        }
        else
        if( person.getXAim() > 0 )
        {
            if( person.getYAim() < 0 )
            {
                leftArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_LEFT_NE;
                rightArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_RIGHT_NE;
            }
            else
            if( person.getYAim() >  0 )
            {
                leftArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_LEFT_SE;
                rightArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_RIGHT_SE;
            }
            else
            {
                leftArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_LEFT_E;
                rightArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_RIGHT_E;
            }

            headGraphicIndexOffset = 2;
        }
        else
        if( person.getYAim() < 0 )
        {
            leftArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_LEFT_N;
            rightArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_RIGHT_N;

            headGraphicIndexOffset = 3;
        }
        else
        if( person.getYAim() >  0 )
        {
            leftArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_LEFT_S;
            rightArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_RIGHT_S;

            headGraphicIndexOffset = 0;
        }
        else
        {
            leftArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_LEFT;
            rightArmGraphicIndex = BlockGraphic.INDEX_BODY_ARM_RIGHT;

            headGraphicIndexOffset = 0;
        }

        // Determine which head graphic to use based on person's velocity.
        xv = person.getXVelocity();
        yv = person.getYVelocity();

        if( xv < 0 )
        {
            headGraphicIndexOffset = 1;
        }
        else
        if( xv > 0 )
        {
            headGraphicIndexOffset = 2;
        }
        else
        {
            if( yv < 0 )
            {
                headGraphicIndexOffset = 3;
            }
            /*
            else
            if( yv > 0 )
            {
                //headGraphicIndexOffset = 0;
            }
            else
            {
                //headGraphicIndexOffset = 0;
            }
            */
        }

        headColor = c64.Info.colorList[c64.Info.COLOR_WHITE];

        // Determine type of person and graphics accordingly.
        // TODO: Determine the block graphics from animation frame/sets.
        if( person.getType() == Person.TYPE_ALLIE )
        {
            headGraphicIndex = BlockGraphic.INDEX_BODY_HEAD_ALLIE_FRONT + headGraphicIndexOffset;
            torsoGraphicIndex = BlockGraphic.INDEX_BODY_TORSO_PRISONER;
            clothesColor = c64.Info.colorList[c64.Info.COLOR_LIGHT_GREEN];
        }
        else
        if( person.getType() == Person.TYPE_NAZI )
        {
            headGraphicIndex = BlockGraphic.INDEX_BODY_HEAD_NAZI_FRONT + headGraphicIndexOffset;
            torsoGraphicIndex = BlockGraphic.INDEX_BODY_TORSO_NAZI;
            clothesColor = c64.Info.colorList[c64.Info.COLOR_YELLOW];
        }
        else
        if( person.getType() == Person.TYPE_SS )
        {
            headGraphicIndex = BlockGraphic.INDEX_BODY_HEAD_NAZI_FRONT + headGraphicIndexOffset;
            torsoGraphicIndex = BlockGraphic.INDEX_BODY_TORSO_SS;
            clothesColor = c64.Info.colorList[c64.Info.COLOR_LIGHT_BLUE];
        }
        else
        {
            headGraphicIndex = BlockGraphic.INDEX_BODY_HEAD_ALLIE_FRONT + headGraphicIndexOffset;
            headColor = c64.Info.colorList[c64.Info.COLOR_DARK_GREY];
            torsoGraphicIndex = BlockGraphic.INDEX_FULL;
            clothesColor = c64.Info.colorList[c64.Info.COLOR_DARK_GREY];
        }

        x = person.getXPosition();
        y = person.getYPosition();

        // Draw head.
        drawBlock( headGraphicIndex, x + 1, y, headColor );

        // Draw the torso.
        drawBlock( torsoGraphicIndex, x + 1, y + 1, clothesColor );

        // Draw the left arm.
        drawBlock( leftArmGraphicIndex, x, y + 1, clothesColor );

        // Draw the right arm.
        drawBlock( rightArmGraphicIndex, x + 2, y + 1, clothesColor );

        // Draw the legs.
        drawBlock( BlockGraphic.INDEX_BODY_LEGS, x + 1, y + 2, clothesColor );
    }

    public void initializeCastle()
    {
        Room newRoom;

        roomList = new Vector<Room>();

        // Create a test room.
        newRoom = new Room();
        newRoom.setId( roomList.size() );
        roomList.add( newRoom );

        // Create another test room.
        newRoom = new Room();
        newRoom.setId( roomList.size() );
        roomList.add( newRoom );

        newRoom.attachRoom( roomList.get( newRoom.getId() - 1 ), Room.SOUTH );

        // Create another test room.
        newRoom = new Room();
        newRoom.setId( roomList.size() );
        roomList.add( newRoom );

        newRoom.attachRoom( roomList.get( newRoom.getId() - 1 ), Room.EAST );

        initializeEnemies();
    }

    public void initializePeople()
    {
        //initializeHero();
    }

    public void initializeHero()
    {
        hero = new Person( Person.TYPE_ALLIE );
        hero.setPosition( 12, 3 );

        // TODO: Will probably need to move this eventually.
        currentRoom = roomList.get( 0 );
        loadCurrentRoom();
    }

    public void initializeEnemies()
    {
        Person enemy;
        Room tempRoom;

        enemyList = new Vector<Person>();

        enemy = new Person( Person.TYPE_NAZI );
        enemy.setPosition( 3, 7 );
        tempRoom = roomList.get( 0 );
        tempRoom.addEntity( enemy );

        enemy = new Person( Person.TYPE_NAZI );
        enemy.setPosition( 15, 10 );
        tempRoom = roomList.get( 1 );
        tempRoom.addEntity( enemy );

        enemy = new Person( Person.TYPE_SS );
        enemy.setPosition( 25, 15 );
        tempRoom = roomList.get( 1 );
        tempRoom.addEntity( enemy );

        enemy = new Person();
        enemy.setPosition( 28, 5 );
        tempRoom = roomList.get( 2 );
        tempRoom.addEntity( enemy );
    }

    public void loadCurrentRoom()
    {
        int index;

        if( currentRoom == null )
        {
            return;
        }

        Vector<Entity> entityList = currentRoom.getEntityList();

        // Load in enemies from this room.
        enemyList.clear();

        for( index = 0; index < entityList.size(); index++ )
        {
            Entity entity = entityList.get( index );

            if( entity instanceof Person )
            {
                int type = entity.getType();

                if( type == Person.TYPE_NAZI )
                {
                    enemyList.add( ( Person )entity );
                }
                else
                if( type == Person.TYPE_SS )
                {
                    enemyList.add( ( Person )entity );
                }
                else
                {
                    // NOTE: Temporary?
                    enemyList.add( ( Person )entity );
                }
            }
            else
            {
                // Probably loading chests and doors here.
            }
        }

        roomNumberText.setString( "Room #" + ( ( Integer )currentRoom.getId() ).toString() );

        // NOTE: Load in rest of room data here?
    }
}
